//
//  HomeTabbarViewController.swift
//  DSHCMerchant
//
//  Created by 罗德良 on 2018/5/15.
//  Copyright © 2018年 袋鼠好车. All rights reserved.
//

import UIKit

class HomeTabbarViewController: YPTabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let target = self.navigationController?.interactivePopGestureRecognizer?.delegate
        let pan:UIPanGestureRecognizer = UIPanGestureRecognizer.init(target: target!, action:nil)
        self.view.addGestureRecognizer(pan)
        
        if UserModel.shareUser.data?.roleId == "1" {//老板权限
            initBossViewControllers()
        }else if UserModel.shareUser.data?.roleId == "2" {//店长权限
            initBossViewControllers()
        }else if UserModel.shareUser.data?.roleId == "3" {//员工
            initEmpolyeeViewControllers()
        }
        
    }
    
//    func configNaiv() -> Void {
//        navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:RGBColorWith(255, green: 255, blue: 255)]
//        navigationController?.navigationBar.isTranslucent = false
//        navigationController?.navigationBar.barTintColor = BaseColor.NavColor
//    }
    func initBossViewControllers() -> Void {
        self.tabBar.itemTitleColor = UIColor.black
        self.tabBar.itemTitleSelectedColor = BaseColor.NavColor
        self.tabBar.delegate = self
        let HomeVC = HomeViewController()
        HomeVC.yp_tabItemTitle = "订单"
        HomeVC.yp_tabItemImage = UIImage.init(named: "home订单_未选择icon")
        HomeVC.yp_tabItemSelectedImage = UIImage.init(named: "home订单_已选择icon")
        
        let storeHomeVC = HomeTwoViewController()
        storeHomeVC.yp_tabItemTitle = "店铺"
        storeHomeVC.yp_tabItemImage = UIImage.init(named: "home店铺_未选择icon")
        storeHomeVC.yp_tabItemSelectedImage = UIImage.init(named: "home店铺_已选择icon")
        
        let serviceVC = PlatformTabBarController()
        serviceVC.yp_tabItemTitle = "修车淘价"
        serviceVC.yp_tabItemImage = UIImage.init(named: "home修车淘价_未选择icon")
        serviceVC.yp_tabItemSelectedImage = UIImage.init(named: "home修车淘价_已选择icon")
        
        let mineVC = SettingViewController()
        mineVC.yp_tabItemTitle = "我的"
        mineVC.yp_tabItemImage = UIImage.init(named: "home我的_未选择icon")
        mineVC.yp_tabItemSelectedImage = UIImage.init(named: "home我的_已选择icon")
        
        self.viewControllers = [HomeVC,storeHomeVC,serviceVC,mineVC]
    }
    
    func initEmpolyeeViewControllers() -> Void {
        self.tabBar.itemTitleColor = UIColor.black
        self.tabBar.itemTitleSelectedColor = BaseColor.NavColor
        self.tabBar.delegate = self
        let HomeVC = HomeViewController()
        HomeVC.yp_tabItemTitle = "订单"
        HomeVC.yp_tabItemImage = UIImage.init(named: "home订单_未选择icon")
        HomeVC.yp_tabItemSelectedImage = UIImage.init(named: "home订单_已选择icon")
        
        let serviceVC = PlatformTabBarController()
        serviceVC.yp_tabItemTitle = "修车淘价"
        serviceVC.yp_tabItemImage = UIImage.init(named: "home修车淘价_未选择icon")
        serviceVC.yp_tabItemSelectedImage = UIImage.init(named: "home修车淘价_已选择icon")
        
        let mineVC = SettingViewController()
        mineVC.yp_tabItemTitle = "我的"
        mineVC.yp_tabItemImage = UIImage.init(named: "home我的_未选择icon")
        mineVC.yp_tabItemSelectedImage = UIImage.init(named: "home我的_已选择icon")
        
        self.viewControllers = [HomeVC,serviceVC,mineVC]
    }
    
    override func didSelectViewController(at index: UInt) {
        print(index)
        if UserModel.shareUser.data?.roleId == "1" {
            if index == 2 {
                let ServiceHomeVC = PlatformTabBarController()
                self.navigationController?.pushViewController(ServiceHomeVC, animated: true)
                selectedControllerIndex = 0
                return
            }
        }else if UserModel.shareUser.data?.roleId == "2" {//店长权限
            if index == 2 {
                let ServiceHomeVC = PlatformTabBarController()
                self.navigationController?.pushViewController(ServiceHomeVC, animated: true)
                selectedControllerIndex = 0
                return
            }
        }else if UserModel.shareUser.data?.roleId == "3" {//员工
            if index == 1 {
                let ServiceHomeVC = PlatformTabBarController()
                self.navigationController?.pushViewController(ServiceHomeVC, animated: true)
                selectedControllerIndex = 0
                return
            }
        }
        
    }
    
//    func yp_tabBar(_ tabBar: YPTabBar!, shouldSelectItemAt index: UInt) -> Bool {
//        <#code#>
//    }
    
}

